package com.zingrow.web.user.service.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.zingrow.web.user.mapper.PermissionMapper;
import com.zingrow.web.user.mapper.UserMapper;
import com.zingrow.web.user.mapper.UserPermissionMapper;
import com.zingrow.web.user.model.Permission;
import com.zingrow.web.user.model.UserPermission;
import com.zingrow.web.user.service.IPermissionService;

@Service("permissionService")
public class PermissionService implements IPermissionService {

	@Autowired
	private PermissionMapper permissionMapper;
	
	@Autowired
	private UserPermissionMapper userpermissionMapper;
	
	@Autowired
	private UserMapper userMapper;
	

	@Override
	public List<Permission> selectbyId(String perId) {

		Map<String, Object> params = new HashMap<String, Object>();

		String[] strArray = null;

		if (perId == null || perId.isEmpty())
			return null;

			strArray = perId.split(",");
		if (strArray != null && strArray.length > 0) {
			params.put("perId", strArray);
			return permissionMapper.selectbyId(params);
		}
		return null;
	}

	@Override
	public UserPermission selectbyuserid(String account){
		return userpermissionMapper.selectByuserId(userMapper.selectByUserAccount(account));
	};
	@Override
	public UserPermission selectbyid(Integer userid){
		return userpermissionMapper.selectbyid(userid);
	}
}
